package com.android.lovingpet;


import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.WindowManager;

import com.android.lovingpet.home.view.HomeActivity;
import com.android.lovingpet.util.Utility;


public class SplashActivity extends AppCompatActivity {

    private final int SPLASH_DISPLAY_LENGHT = 2000;
    private Handler handler;
    private String sessionId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        sessionId = Utility.getJSessionId();
        super.onCreate(savedInstanceState);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);
        handler=new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //判断sharedPreference中是否存有sessionId，有则已登陆,直接跳转主界面
                if (TextUtils.isEmpty(sessionId) || (Utility.getAccount() == null && Utility.getTeam() == null))
                {
                    Intent intent = new Intent(SplashActivity.this, StartActivity.class);
                    startActivity(intent);
                }
                else {
                    Intent intent=new Intent(SplashActivity.this, HomeActivity.class);
                    startActivity(intent);
                }
                SplashActivity.this.finish();
            }
        },SPLASH_DISPLAY_LENGHT);


    }
}
